package com.example.map.myapplication;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentActivity;
import android.support.v4.widget.SlidingPaneLayout;
import android.view.View;

import com.tencent.smtt.sdk.WebSettings;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;

public class MainActivity extends FragmentActivity implements BookMarkerFragment.BookmarkListener{


 SlidingPaneLayout spl = null;

    public Handler getmHandler() {
        return mHandler;
    }

    Handler mHandler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case 0:
                    fragmentById.getWebView().loadUrl("http://www.cnblogs.com/wade-pcb/p/4646017.html");
                    break;
                case 1:
                    fragmentById.getWebView().loadUrl("http://blog.csdn.net/zshq280017423/article/details/8928616");
                    break;
                case 2:
                    fragmentById.getWebView().loadUrl("http://blog.csdn.net/pk0071/article/details/51112642");
                    break;
                case 3:
                    fragmentById.getWebView().loadUrl("http://blog.csdn.net/huangyabin001/article/details/35231753");
                    break;
            }
        }
    };
    private ShowFragment fragmentById;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         fragmentById = (ShowFragment)MainActivity.this.getFragmentManager()
                .findFragmentById(R.id.rightfragment);
        spl = (SlidingPaneLayout) this.findViewById(R.id.slidingpanellayout);
        spl.setPanelSlideListener(new SlidingPaneLayout.PanelSlideListener() {
            @Override
            public void onPanelClosed(View view) {
                MainActivity.this.getFragmentManager()
                        .findFragmentById(R.id.leftfragment)
                        .setHasOptionsMenu(false);
            }

            @Override
            public void onPanelOpened(View viw) {
                MainActivity.this.getFragmentManager()
                        .findFragmentById(R.id.leftfragment)
                        .setHasOptionsMenu(true);
            }

            @Override
            public void onPanelSlide(View arg0, float arg1) {

            }
        });
    }
//    public void add(View view){
//        getSupportFragmentManager().beginTransaction().replace(R.id.fl,new A()).commit();
//
//    }
    public void inter(View view) {


        Message msg = new Message();
        msg.obj = "A";
        msg.what = 1;
        mHandler.sendMessage(msg);
    }
    public void setHandler(Handler handler) {
        mHandler = handler;
    }
   @Override
    public void onChangeBookmark(String bookmark) {
        ShowFragment sf = (ShowFragment) MainActivity.this.getFragmentManager()
                .findFragmentById(R.id.rightfragment);
        WebView webView = sf.getWebView();
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        WebViewClient client = new WebViewClient();
        webView.setWebViewClient(client);
        webView.loadUrl(bookmark);

    }

}
